package com.vastio.realm;

import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.SimpleAuthenticationInfo;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;
import org.apache.shiro.util.ByteSource;

/**
 * @author hjwStart
 * @time 2022-11-21 15:29
 * @version: 1.0
 */
public class MyRealm extends AuthorizingRealm {
    @Override
    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
        return null;
    }

    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {

        String userName = authenticationToken.getPrincipal().toString();
        String userPwd = authenticationToken.getCredentials().toString();
        SimpleAuthenticationInfo authenticationInfo = null;
        if ("admin".equals(userName)) {
            authenticationInfo = new SimpleAuthenticationInfo(userName, "79ae1231b5934424660a8e5f2aa91393",
                    ByteSource.Util.bytes("salt"), this.getName());
        }
        return authenticationInfo;
    }
}
